package com.fengye.algorithms.huawei;

import java.util.Scanner;

/**
 * https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841?tpId=37&tqId=21243&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=
 * @Author fengye
 * @Date 2023/4/7 10:31
 **/
public class PasswordCheckMain {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            String password = in.next();
            if (password.length() <= 8) {
                System.out.println("NG");
                continue;
            }
            char[] chars = password.toCharArray();
            boolean hasNumber = false;
            boolean hasLowercase = false;
            boolean hasUppercase = false;
            boolean hasOther = false;
            for (char ch : chars) {
                if (isNumeric(ch)) {
                    hasNumber = true;
                    continue;
                }
                if (isLowerCase(ch)) {
                    hasLowercase = true;
                    continue;
                }
                if (isUpperCase(ch)) {
                    hasUppercase = true;
                    continue;
                }
                hasOther = true;
            }

            int num = 0;
            if (hasOther) {
                num++;
            }

            if (hasLowercase) {
                num++;
            }

            if (hasNumber) {
                num++;
            }

            if (hasUppercase) {
                num++;
            }

            if (num < 3) {
                System.out.println("NG");
                continue;
            }
            boolean hasNG  = false;
            for (int i = 0; i + 3 <= password.length(); i++) {
                String sub = password.substring(i, i + 3);
                String lastSub = password.substring(i + 1);
                if (lastSub.contains(sub)) {
                    System.out.println("NG");
                    hasNG = true;
                    break;
                }
            }

            if (!hasNG) {
                System.out.println("OK");
            }
        }
    }

    /**
     * 是否大写
     * @param ch
     * @return
     */
    private static boolean isUpperCase(char ch) {
        if (ch >= 'A' && ch <= 'Z') {
            return true;
        }
        return false;
    }

    /**
     * 是否小写
     * @param ch
     * @return
     */
    private static boolean isLowerCase(char ch) {
        if (ch >= 'a' && ch <= 'z') {
            return true;
        }
        return false;
    }

    /**
     * 是否是数字
     *
     * @param ch
     * @return
     */
    private static boolean isNumeric(char ch) {
        if (ch >= '0' && ch <= '9') {
            return true;
        }
        return false;
    }
}
